
#ifndef __BACKUPMODULE_H__
#define __BACKUPMODULE_H__

#include "RtUtilTemplates.h"
#include "BackupBase.h"

class RT_API_EXPORT CBackupModule
: public CBackupBase<CBackupModule>
{
public:
	static CBackupModule* Instance();
	virtual  RtResult Initialize(
					const CRtString& strPeerIP, 
					WORD nPeerPort, 
					const CRtString& strGroupName, 
					const CRtString& strClusterID,
					BackupModuleSink* pSink);
	virtual  void Release();
	virtual  void OnNodeJoin(DWORD dwNodeID);

	BOOL IsActive() { return m_bActive; }

protected:
	typedef CBackupBase<CBackupModule> SuperType;
	friend class CBackupBase<CBackupModule>;
	friend class CRtSingletonT<CBackupModule>;
	CBackupModule();
	~CBackupModule();

	void HandlePdu(DWORD dwNodeID, WORD nType, CMrPduBase& pdu);
	void OnControllerTimer_i(LONGLONG dwCurrentTick);

	void OnNegotiate(DWORD dwNodeID, CMrPduBase& pdu);

	void Activate(BOOL bFailover=FALSE);
	void Deactivate();

protected:
	BOOL m_bActive;
	LONGLONG m_dwActiveTimestamp;
	LONGLONG m_dwActiveDuration;
};

typedef CRtSingletonT<CBackupModule> CBackupModuleSingleton;

#endif // __BACKUPMODULE_H__
